/**
 * Created by zhangzhihao on 2016/12/06 11:00;
 */
var vm = new Vue({
    el: '#main',
    data: {
		checkDatas : [],
		pagination: [],
		organCode: '',
		organCodeName:'',
       	nowPage:1,
		RowNum:10,
		zTree:null,
		pageNum: ''
    },
    created: function () {
		this.search();
		this.initZtree();
    },
    methods: {
		selectPage:function(page){
            this.nowPage = page;
            this.search();
		},
		offsetPage:function(offset){
            this.nowPage = this.nowPage + offset;
            this.search();
        },
    	search:function(){
			var data = {
				nowPage:this.nowPage,
				rowNum:this.RowNum,
				organCode: this.organCode,
				startTime:$('#beginDay').val(),
				endTime:$('#endDay').val(),
			};
			axios({
				method: 'post',
				url: App.envUrl.backtrackUrl + 'check/getDataCount',
				data: data,
			})
			.then((data) => {
				if(data.data.pageCount && data.data.pageCount.datas && data.data.pageCount.datas.length>0){
					vm.checkDatas = data.data.pageCount.datas;
				} else {
					vm.checkDatas = [];
				}
				vm.pagination = getPagination(this.nowPage,data.data.pageCount.allPages);
			})
			.catch((err) => {});
    	},
        //新增按钮
        addBtn:function(){
        	location.href = './nrrtask_add.html';
		},
		check_c:function(){
			this.search();
		},
        //重置按钮
        check_r:function(){
            window.location.reload();
		},
		chooseOrg(){
			$('#orgTree').modal({
				relatedTarget: this,
			});
		},
		chooseBtnClick(){
			var node = this.zTree.getSelectedNodes()[0];
			this.organCodeName = node.branchName;
			this.organCode = node.branchId;
		},
		initZtree(){
			var setting = {
				data: {
					simpleData: {
						enable: true,
						idKey: "branchId",
						pIdKey: "branchParentid"
					},
					key: {
						name: "branchName"
					}
				},
				view: {
					dblClickExpand: false,
					showLine: true,
					showIcon: true,
					selectedMulti: false
				}
			};
			axios({
				method: 'post',
				url: App.envUrl.backtrackUrl + 'check/getBranchList',
			})
			.then((data) => {
				if(data.data && data.data.data && data.data.data.length>0){
					$.fn.zTree.init($("#menuTree"), setting, data.data.data);
					vm.zTree = $.fn.zTree.getZTreeObj("menuTree");
					vm.rMenu = $("#menuTree");
				}
			})
			.catch((err) => {});
		}
    }
});

function changeRowNum(){
	vm.RowNum = $('#RowNum').val();
	vm.search();
}